<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="名称" style="display: inline-block">
        <el-input v-model="form.name" style="width: 221px"></el-input>
      </el-form-item>
      <el-form-item label="类型" style="display: inline-block; width: auto">
        <el-input v-model="form.type" style="width: 221px"></el-input>
      </el-form-item>

      <el-button type="primary" @click="findPage" style="display: inline-block"
        >查询</el-button
      >
    </el-form>
    <el-button type="primary" @click="toadd">添加</el-button>
    <el-table
      @selection-change="fx"
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column type="selection" width="55"> </el-table-column>

      <el-table-column prop="id" label="ID"> </el-table-column>
      <el-table-column prop="stationId" label="充电站编号"> </el-table-column>

      <el-table-column prop="stationName" label="充电站名称"> </el-table-column>

      <el-table-column prop="stationType" label="充电站类型"> </el-table-column>
      <el-table-column prop="stationLocation" label="电站位置">
      </el-table-column>
      <el-table-column prop="num" label="充电桩数量"> </el-table-column>
      <el-table-column prop="tbUserId" label="电站负责人"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="del(scope.row.id)"
            type="danger"
            icon="el-icon-delete"
            circle
          ></el-button>
          <el-button type="text" size="small" @click="toupdate(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[2, 4, 6, 8]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 2,
      form: {},
    };
  },
  created() {
    this.findPage();
  },
  methods: {
    toadd(){
      this.$router.push({
        path: '/saveCharge'
      })
    },
    findPage() {
      axios
        .post(
          `/bdc/bdc/getChargingStationList/${this.pageNum}/${this.pageSize}`,
          this.form
        )
        .then((res) => {
          this.tableData = res.data.records;
          this.total = res.data.total;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findPage();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.findPage();
    },
    fx(val) {
      this.aids = val;
    },
  },
};
</script>

<style>
</style>